
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.sql.ResultSet"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="br.com.integrator.util.ConnectionFactory"%>
<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="CSS/style.css" rel="stylesheet" type="text/css" />
        <title>Lista de Revistas</title>
    </head>
    <body style="background-color:#E2E4E4">
        <c:import url="_templates/header.jsp" />
        <div class="conteudo">   
            <h1>Lista de Revistas</h1>
            <table border='1'>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Nome</th>               
                    <th>Editora</th>
                    <th>Preço</th>
                    <th>Edição</th>                

                </tr>
                <%
                    Connection con = null;
                    Statement stmt = null;
                    ResultSet rs = null;
                    SimpleDateFormat format = new SimpleDateFormat("yyyy");
                    try {
                        con = ConnectionFactory.getConnection();
                        stmt = con.createStatement();
                        rs = stmt.executeQuery("Select * from REVISTAS order by id asc");
                        while (rs.next()) {
                            String id = rs.getString("ID");
                            String dtFormatada = (rs.getDate("EDICAO") == null) ? "" : format.format(rs.getDate("EDICAO"));
                            out.println("<tr>");
                            out.println("<td><img alt=\"img\" src=\"Imagens/revista.jpg\" style=\"cursor: pointer;\" /><//td>");
                            out.println("<td>" + id + "</td>");
                            //out.println("<td>"+id+"</td>");
                            out.println("<td>" + rs.getString("NOME") + "</td>");
                            out.println("<td>" + rs.getString("EDITORA") + "</td>");
                            out.println("<td>" + rs.getDouble("PRECO") + "</td>");
                            out.println("<td>" + dtFormatada + "</td>");
                            out.println("</tr>");
                        }
                    } catch (Exception ex) {
                        out.println("<tr><td colspan='3'>ERRO: " + ex.getMessage() + "</tr>");
                    } finally {
                        try {
                            rs.close();
                        } catch (Exception e) {
                        }
                        try {
                            stmt.close();
                        } catch (Exception e) {
                        }
                        try {
                            con.close();
                        } catch (Exception e) {
                        }
                    }
                %>
            </table>
        </div>        
        <c:import url="_templates/footer.jsp" />
    </body>
</html>
